/*
XPTracker - Alternative Agile Tracking Tool
Copyright (C) 2006-2009  Stephen Starkey

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
*/
package org.xptracker.services.reports;

import org.xptracker.persistence.DomainRegistry;
import org.xptracker.persistence.Identified;
import org.xptracker.persistence.ObjectChange;
import org.xptracker.persistence.PersistenceManager;

import java.util.*;

public class MockPersistenceManager implements PersistenceManager {
  private Map<String, List<ObjectChange>> changes = new HashMap<String, List<ObjectChange>>();

  public String getDbType() {
    return "mock";
  }

  public void initialize(DomainRegistry domainRegistry) {
  }

  public void shutdown() {
  }

  public void doMaintenance() {
  }

  public <T> T inTransaction(UpdateHandler<T> handler) {
    return null;
  }

  public <T> List<T> query(String query) {
    return null;
  }

  public <T> List<T> query(String query, Map<String, Object> args) {
    return null;
  }

  public <T> List<T> queryWithScript(String query, Object... args) {
    return null;
  }

  public void flush() {
    //noop
  }

  public <T extends Identified> List<T> listObjects(Class<T> objectClass, Set<String> ids) {
    return null;
  }

  public <T> T loadObject(Class<? extends T> entityType, String id) {
    return null;
  }

  public <T> T loadObject(Class<? extends T> entityType, String id, FetchHelper<T> helper) {
    throw new UnsupportedOperationException();
  }

  public void addChange(String id, ObjectChange change) {
    getChanges(id).add(change);
  }

  private List<ObjectChange> getChanges(String id) {
    List<ObjectChange> changes = this.changes.get(id);
    if (changes == null) {
      changes = new ArrayList<ObjectChange>();
      this.changes.put(id, changes);
    }
    return changes;
  }
}
